using System;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("status", "Print the status of working copy files and directories.", AltName = "st", MaxArgs = 1, UsageSummary = "[path] [options]",
        UsageDescription = @"The first column contains local change information:
     Not modified
  ?  Not under version control
  !  Local file is missing
  A  Added
  C  Conflicted
  D  Deleted
  M  Modified

The second column contains remote change information (with /server):
     Not modified
  +  Added
  *  Updated
  -  Deleted

The third column contains the local change set ID (with /verbose).

The fourth column contains the remote change set ID (with /verbose /server).")]
    public class StatusCommand : AuthenticatedCommand
    {
        bool connectToServer;
        bool? gui;
        bool nonRecursive;
        bool verbose;

        //[Option("server", "display server information", ShortName = "s")]
        public bool ConnectToServer
        {
            get { return connectToServer; }
            set { connectToServer = value; }
        }

        [Option("gui", "launch (don't launch) status GUI", ShortName = "g", ShowPlusMinus = true)]
        public bool Gui
        {
            get { return gui.HasValue ? gui.Value : Config.DefaultToGuiForStatus; }
            set { gui = value; }
        }

        [Option("non-recursive", "do not recurse into subdirectories", ShortName = "n")]
        public bool NonRecursive
        {
            get { return nonRecursive; }
            set { nonRecursive = value; }
        }

        [Option("verbose", "display verbose information", ShortName = "v")]
        public bool Verbose
        {
            get { return verbose; }
            set { verbose = value; }
        }

        public override void Execute()
        {
            if (Gui && NonInteractive)
            {
                Console.WriteLine("error: /gui and /non-interactive are mutually exclusive");
                return;
            }

            if (Gui && ConnectToServer)
            {
                Console.WriteLine("error: /server is not support for /gui (yet)");
                return;
            }

            string targetPath = ".";

            if (Arguments.Count > 0)
                targetPath = Arguments[0];

            string localPath = CodePlexClientUtil.GetFullPath(targetPath);

            IStatusView view;

            if (Gui)
                view = new StatusGuiView(Engine, localPath, Verbose, !NonRecursive, ConnectToServer, Config.DiffTool,
                                         Config.DiffArgs, Config.MergeTool, Config.MergeArgs);
            else
                view = new StatusConsoleView(Engine, localPath, Verbose, !NonRecursive, ConnectToServer);

            view.Run();
        }
    }
}